package com.xuexiang.xuidemo.slice;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Image;

import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.slice.layout.AlphaViewAbilitySlice;
import com.xuexiang.xuidemo.slice.layout.ExpandableLayoutAbilitySlice;
import com.xuexiang.xuidemo.slice.layout.GroupListViewAbilitySlice;
import com.xuexiang.xuidemo.slice.layout.LinkageScrollLayoutAbilitySlice;
import com.xuexiang.xuidemo.slice.layout.XUILayoutAbilitySlice;

public class LayoutAbilitySlice extends AbilitySlice implements Component.ClickedListener {

    private DirectionalLayout alphaButton, XUILayoutButton, XUIGroupButton, strechButton, linkageButton;


    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_layout_main);
        initView();
    }

    private void initView() {
        alphaButton = (DirectionalLayout) findComponentById(ResourceTable.Id_alphaButton);
        XUILayoutButton = (DirectionalLayout) findComponentById(ResourceTable.Id_XUILayoutButton);
        XUIGroupButton = (DirectionalLayout) findComponentById(ResourceTable.Id_XUIGroupButton);
        strechButton = (DirectionalLayout) findComponentById(ResourceTable.Id_strechButton);
        linkageButton = (DirectionalLayout) findComponentById(ResourceTable.Id_linkageButton);
        alphaButton.setClickedListener(this);
        XUILayoutButton.setClickedListener(this);
        XUIGroupButton.setClickedListener(this);
        strechButton.setClickedListener(this);
        linkageButton.setClickedListener(this);

        Image backImage = (Image) findComponentById(ResourceTable.Id_backImage);
        backImage.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                terminate();
            }
        });
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_alphaButton:
                present(new AlphaViewAbilitySlice(), new Intent());
                break;
            case ResourceTable.Id_XUILayoutButton:
                present(new XUILayoutAbilitySlice(), new Intent());
                break;
            case ResourceTable.Id_XUIGroupButton:
                present(new GroupListViewAbilitySlice(), new Intent());
                break;
            case ResourceTable.Id_strechButton:
                present(new ExpandableLayoutAbilitySlice(), new Intent());
                break;
            case ResourceTable.Id_linkageButton:
                present(new LinkageScrollLayoutAbilitySlice(), new Intent());
                break;
        }

    }
}

